﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using TyMES.Model.Record;
using TyMES.Model;

namespace TyMES.ViewModel.Record.BadProductRecordVMs
{
    public partial class BadProductRecordListVM : BasePagedListVM<BadProductRecord_View, BadProductRecordSearcher>
    {
        
        protected override IEnumerable<IGridColumn<BadProductRecord_View>> InitGridHeader()
        {
            return new List<GridColumn<BadProductRecord_View>>{
                
                this.MakeGridHeader(x => x.BadProductRecord_factoryCode).SetTitle(@Localizer["Page.工厂编码"].Value),
                this.MakeGridHeader(x => x.BadProductRecord_lineCode).SetTitle(@Localizer["Page.产线编码"].Value),
                this.MakeGridHeader(x => x.BadProductRecord_snNumber).SetTitle(@Localizer["Page.SN号"].Value),
                this.MakeGridHeader(x => x.BadProductRecord_stationCode).SetTitle(@Localizer["Page.工位编号"].Value),
                this.MakeGridHeader(x => x.BadProductRecord_materialCode).SetTitle(@Localizer["Page.物料编码"].Value),
                this.MakeGridHeader(x => x.BadProductRecord_materialName).SetTitle(@Localizer["Page.物料名称"].Value),
                this.MakeGridHeader(x => x.BadProductRecord_materialVersion).SetTitle(@Localizer["Page.物料版本"].Value),
                this.MakeGridHeader(x => x.BadProductRecord_operationCode).SetTitle(@Localizer["Page.工序编码"].Value),
                this.MakeGridHeader(x => x.BadProductRecord_defectSource).SetTitle(@Localizer["Page.不良信息源"].Value),
                this.MakeGridHeader(x => x.BadProductRecord_UploadFlag).SetTitle(@Localizer["Page.上传标志"].Value),
                this.MakeGridHeader(x => x.BadProductRecord_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.BadProductRecord_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.BadProductRecord_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.BadProductRecord_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<BadProductRecord_View> GetSearchQuery()
        {
            var query = DC.Set<BadProductRecord>()
                
                .CheckContain(Searcher.FactoryCode, x=>x.FactoryCode)
                .CheckContain(Searcher.LineCode, x=>x.LineCode)
                .CheckContain(Searcher.SnNumber, x=>x.SnNumber)
                .CheckContain(Searcher.StationCode, x=>x.StationCode)
                .CheckContain(Searcher.MaterialCode, x=>x.MaterialCode)
                .CheckContain(Searcher.MaterialName, x=>x.MaterialName)
                .CheckContain(Searcher.MaterialVersion, x=>x.MaterialVersion)
                .CheckContain(Searcher.OperationCode, x=>x.OperationCode)
                .CheckContain(Searcher.DefectSource, x=>x.DefectSource)
                .CheckEqual(Searcher.UploadFlag, x=>x.UploadFlag)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new BadProductRecord_View
                {
				    ID = x.ID,
                    
                    BadProductRecord_factoryCode = x.FactoryCode,
                    BadProductRecord_lineCode = x.LineCode,
                    BadProductRecord_snNumber = x.SnNumber,
                    BadProductRecord_stationCode = x.StationCode,
                    BadProductRecord_materialCode = x.MaterialCode,
                    BadProductRecord_materialName = x.MaterialName,
                    BadProductRecord_materialVersion = x.MaterialVersion,
                    BadProductRecord_operationCode = x.OperationCode,
                    BadProductRecord_defectSource = x.DefectSource,
                    BadProductRecord_UploadFlag = x.UploadFlag,
                    BadProductRecord_CreateTime = x.CreateTime,
                    BadProductRecord_UpdateTime = x.UpdateTime,
                    BadProductRecord_CreateBy = x.CreateBy,
                    BadProductRecord_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class BadProductRecord_View: BadProductRecord
    {
        
        public string BadProductRecord_factoryCode { get; set; }
        public string BadProductRecord_lineCode { get; set; }
        public string BadProductRecord_snNumber { get; set; }
        public string BadProductRecord_stationCode { get; set; }
        public string BadProductRecord_materialCode { get; set; }
        public string BadProductRecord_materialName { get; set; }
        public string BadProductRecord_materialVersion { get; set; }
        public string BadProductRecord_operationCode { get; set; }
        public string BadProductRecord_defectSource { get; set; }
        public bool? BadProductRecord_UploadFlag { get; set; }
        public DateTime? BadProductRecord_CreateTime { get; set; }
        public DateTime? BadProductRecord_UpdateTime { get; set; }
        public string BadProductRecord_CreateBy { get; set; }
        public string BadProductRecord_UpdateBy { get; set; }

    }

}